package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.DataCase;
import com.ruoyi.system.service.IDataCaseService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 客户案例管理Controller
 * 
 * @author hak
 * @date 2024-11-13
 */
@RestController
@RequestMapping("/case")
public class DataCaseController extends BaseController
{
    @Autowired
    private IDataCaseService dataCaseService;

    /**
     * 查询客户案例管理列表
     */
    @RequiresPermissions("system:case:list")
    @GetMapping("/list")
    public TableDataInfo list(DataCase dataCase)
    {
        startPage();
        List<DataCase> list = dataCaseService.selectDataCaseList(dataCase);
        return getDataTable(list);
    }

    /**
     * 导出客户案例管理列表
     */
    @RequiresPermissions("system:case:export")
    @Log(title = "客户案例管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DataCase dataCase)
    {
        List<DataCase> list = dataCaseService.selectDataCaseList(dataCase);
        ExcelUtil<DataCase> util = new ExcelUtil<DataCase>(DataCase.class);
        util.exportExcel(response, list, "客户案例管理数据");
    }

    /**
     * 获取客户案例管理详细信息
     */
    @RequiresPermissions("system:case:query")
    @GetMapping(value = "/{caseId}")
    public AjaxResult getInfo(@PathVariable("caseId") Long caseId)
    {
        return success(dataCaseService.selectDataCaseByCaseId(caseId));
    }

    /**
     * 新增客户案例管理
     */
    @RequiresPermissions("system:case:add")
    @Log(title = "客户案例管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataCase dataCase)
    {
        return toAjax(dataCaseService.insertDataCase(dataCase));
    }

    /**
     * 修改客户案例管理
     */
    @RequiresPermissions("system:case:edit")
    @Log(title = "客户案例管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DataCase dataCase)
    {
        return toAjax(dataCaseService.updateDataCase(dataCase));
    }

    /**
     * 删除客户案例管理
     */
    @RequiresPermissions("system:case:remove")
    @Log(title = "客户案例管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{caseIds}")
    public AjaxResult remove(@PathVariable Long[] caseIds)
    {
        return toAjax(dataCaseService.deleteDataCaseByCaseIds(caseIds));
    }
}
